function [U1,U2,bondprice,bidask_bond,priceimpactbond,bidask_cds,riskfreerate,CDS_basis] = output_bondonly(controls,pi1,w1,w2,y1vec,y2vec,yf,gamma,gammaf,relativesize,bondpayoff,pCDS)
%This function computes equilibrium outcomes for the bond-only economy

a1=controls(1); %asset positions of Type 1
a2=-a1;%Back out from market clearing with a small fringe
af=controls(2);

pivec=[pi1,1-pi1];

cf=yf+bondpayoff*af;


pricesAD=pivec.*(cf).^(-gammaf); %Prices
riskfreerate=100*(1/sum(pricesAD)-1);

bondprice= (1-pi1).*bondpayoff(2).*(cf(2)).^(-gammaf); %Prices

Cbondprice=sum(pivec.*bondpayoff.*(cf).^(-gammaf)); %Prices


c01=w1-Cbondprice*a1; %Type 1 consumption within the period
c02=w2-Cbondprice*a2; %Type 2 consumption within the period

c1prime=y1vec+bondpayoff*a1; %Type 1: 1x2 vector of state-contingent updated wealth
c2prime=y2vec+bondpayoff*a2; %Type 2: 1x2 vector of state-contingent updated wealth


if gamma==1
    
    U1=log(c01) + pi1*log(c1prime(1)) + (1-pi1)*log(c1prime(2));
    U2=log(c02) + pi1*log(c2prime(1)) + (1-pi1)*log(c2prime(2));

else
    
    U1=((c01)^(1-gamma))/(1-gamma) + pi1*((c1prime(1))^(1-gamma))/(1-gamma) + (1-pi1)*((c1prime(2))^(1-gamma))/(1-gamma);
    U2=((c02)^(1-gamma))/(1-gamma) + pi1*((c2prime(1))^(1-gamma))/(1-gamma) + (1-pi1)*((c2prime(2))^(1-gamma))/(1-gamma);

end

cdsprice=pi1*bondpayoff(2)*(cf(1))^(-gammaf);
priceimpactbond=relativesize*gammaf*(1-pi1).*(bondpayoff(2).^2).*(cf(2)).^(-gammaf-1);

cdsvolume=2*abs(a1(1));

% Compute state prices

Lambda1=(pivec.* c1prime.^(-gamma))./(c01^(-gamma));
Lambda2=(pivec.* c2prime.^(-gamma))./(c02^(-gamma));

% %Alternative:
% 
bidask_bond= (Lambda1(2) - Lambda2(2)) / cdsvolume; %fraction of par
bidask_cds= cdsvolume \ bondpayoff(2) * (Lambda1(1)-Lambda2(1)) /  cdsprice;

CDS_basis = (pi1 * bondpayoff(2) / cdsprice - (1 - pi1) * bondpayoff(2) / bondprice) / cdsvolume;

end

